import 'package:intl/intl.dart' show DateFormat;

/// 时间工具
class DateUtils {
  DateUtils._();

  static final DateUtils _singleton = DateUtils._();

  factory DateUtils() => _singleton;

  String format(final String format, final DateTime? date) {
    if (format.isNotEmpty && date != null) {
      final dateFormat = DateFormat(format);
      return dateFormat.format(date);
    }
    return '';
  }

  DateTime? parse(final String format, final String? val) {
    if (format.isNotEmpty && val != null && val.isNotEmpty) {
      final dateFormat = DateFormat(format);
      return dateFormat.parse(val);
    }
    return null;
  }
}

/// 时间工具单例
final dateUtils = DateUtils();
